136. Single Number

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

You must implement a solution with a linear runtime complexity and use only constant extra space.

 

Example 1:

Input: nums = [2,2,1]
Output: 1

Example 2:

Input: nums = [4,1,2,1,2]
Output: 4

Example 3:

Input: nums = [1]
Output: 1

 

Constraints:

  • 1 <= nums.length <= 3 * 104
  • -3 * 104 <= nums[i] <= 3 * 104
  • Each element in the array appears twice except for one element which appears only once.
#1 Two Sum
Easy
#2 Add Two Numbers
Medium
#3 Longest Substring Without Repeating Characters
Medium
#4 Median of Two Sorted Arrays
Hard
#5 Longest Palindromic Substring
Medium
#6 Zigzag Conversion
Medium
#7 Reverse Integer
Medium
#8 String to Integer (atoi)
Medium
#9 Palindrome Number
Easy
#10 Regular Expression Matching
Hard
#11 Container With Most Water
Medium
#12 Integer to Roman
Medium
#13 Roman to Integer
Easy
#14 Longest Common Prefix
Easy
#15 3Sum
Medium
#16 3Sum Closest
Medium
#17 Letter Combinations of a Phone Number
Medium
#18 4Sum
Medium
#19 Remove Nth Node From End of List
Medium
#20 Valid Parentheses
Easy
#21 Merge Two Sorted Lists
Easy
#22 Generate Parentheses
Medium
#23 Merge k Sorted Lists
Hard
#24 Swap Nodes in Pairs
Medium
#25 Reverse Nodes in k-Group
Hard
#26 Remove Duplicates from Sorted Array
Easy
#27 Remove Element
Easy
#28 Find the Index of the First Occurrence in a String
Medium
#29 Divide Two Integers
Medium
#30 Substring with Concatenation of All Words
Hard
#31 Next Permutation
Medium
#32 Longest Valid Parentheses
Hard
#33 Search in Rotated Sorted Array
Medium
#34 Find First and Last Position of Element in Sorted Array
Medium
#35 Search Insert Position
Easy
#36 Valid Sudoku
Medium
#37 Sudoku Solver
Hard
#38 Count and Say
Medium
#39 Combination Sum
Medium
#40 Combination Sum II
Medium
#41 First Missing Positive
Hard
#42 Trapping Rain Water
Hard
#43 Multiply Strings
Medium
#44 Wildcard Matching
Hard
#45 Jump Game II
Medium
#46 Permutations
Medium
#47 Permutations II
Medium
#48 Rotate Image
Medium
#49 Group Anagrams
Medium
#50 Pow(x, n)
Medium